import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 引入js文件
import msiteRouter from '../router/msite'
import searchRouter from '../router/search'
import rankingRouter from '../router/ranking'
import wowRouter from '../router/wow'
import orderRouter from '../router/order'
import discoverRouter from '../router/discover'
import profileRouter from '../router/profile'
import addresstwoRouter from '../router/addresstwo'
import footRouter from '../router/foot'
import shopRouter from '../router/shop'
import erweimaRouter from '../router/erweima'
import myRouter from '../router/my'

const routes = [
  msiteRouter,
  searchRouter,
  rankingRouter,
  wowRouter,
  orderRouter,
  discoverRouter,
  profileRouter,
  addresstwoRouter,
  footRouter,
  shopRouter,
  erweimaRouter,
  myRouter,
]


const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.meta.isAuthorization){
     //验证身份
     if(localStorage.token){
        next()
     }
     else{
        next('/profile')
     }
    
  }
  else{
     next()
    
  }
})
export default router
